#!/usr/bin/perl -w
#   Written by Jimmy Saw - 10-11-2007
#   This program takes a Genbank file and extract coordinates of genes 
#   You have to redirect output to a file

use Bio::SeqIO;

my $seqio_obj = Bio::SeqIO->new (-file => $ARGV[0], -format => 'genbank');
my $seq_obj;
my @seq_array;

while ($seq_obj = $seqio_obj->next_seq()){
    push (@seq_array, $seq_obj);
}

my $total = 0;
my $countseq = 0;

foreach $seq_obj (@seq_array){

    my $count = 0;

    for my $feat_obj ($seq_obj->get_SeqFeatures){

#        $count++;

        if ($feat_obj->primary_tag eq "CDS"){

            $count++;

            if ($feat_obj->has_tag('product')){
                for my $value ($feat_obj->get_tag_values('locus_tag')){
                  if($feat_obj->strand == 1){
                    print $value, "\t", $feat_obj->get_tag_values('product'), "\t", $feat_obj->start, "\t", $feat_obj->end, "\t", $feat_obj->strand, "\t", $feat_obj->end - $feat_obj->start + 1, "\t", $feat_obj->seq->seq(), "\t", $feat_obj->get_tag_values('translation'), "\n";
                  }
                  else {
                    print $value, "\t", $feat_obj->get_tag_values('product'), "\t", $feat_obj->end, "\t", $feat_obj->start, "\t", $feat_obj->strand, "\t", $feat_obj->end - $feat_obj->start + 1, "\t", $feat_obj->seq->seq(), "\t", $feat_obj->get_tag_values('translation'), "\n";
                  }
                }
            }
        }
    }
}

